import { approvalApi } from "@/api/waybillManagement/quotationApproval";
import FormHook from "@/hook/formHook";
import { GeneraDataType } from "@/interface";
import { message } from "ant-design-vue";
export default function OperationHook(state: GeneraDataType) {
  const { formState, formDataRef, emit, passData, loading } = state;
  const { resetFields } = FormHook({ formState });
  const submitHandle = (type: number) => {
    formDataRef.value.validate().then(() => {
      const params = {
        ...formState,
        id: passData.value.id
      };
      loading.value = true;
      approvalApi(params)
        .then((res: any) => {
          const { code } = res;
          if (code === 200) {
            message.success("驳回成功!");
            emit("submit", type);
          }
        })
        .finally(() => (loading.value = false));
    });
  };
  const resetHandle = () => {
    resetFields();
    formDataRef.value.clearValidate();
    emit("update:visible", false);
  };
  return {
    submitHandle,
    resetHandle,
    resetFields
  };
}
